Question Excel VBA to VB.Net Conversion Problem

jcleary47

New member
Joined
Nov 12, 2009
Messages
1
Programming Experience
Beginner
Hello,

My first time registering and posting on the site so hello to everyone. Sorry in advance if this should go under a different section.

I have a piece of code that isn't cooperating in converting a VBA excel macro I have that is going into a VB.Net program. Essentially, the code searches for columns with a specific heading in Row 1 and deletes the entire column if the heading name is present.

Example of the VBA code:

VB.NET:
sToFind = "Column Heading Name1"
Do
Set rngFound = wstTarget.Rows(1).Find( _
    What:=sToFind, _
    LookIn:=xlValues, _
    lookat:=xlWhole)
If rngFound Is Nothing Then
Exit Do
Else
    rngFound.EntireColumn.Delete
End If
Loop

I know that the first part that stood out to me as having an issue is the:

VB.NET:
Set rngFound = wstTarget.Rows(1).Find( _
    What:=sToFind, _
    LookIn:=xlValues, _
    lookat:=xlWhole)

I've scoured google and forums but I don't see a possible translation for the LookIn and LookAt and I'm sure that whole piece of code in general isn't translating well at all.

This is literally the last piece of code I need to get working and it's driving me up a wall. I'll also mention I am quite the beginner at all of this so I'm sorry in advance for any lack of knowledge I may display :eek:
 
LookIn and LookAt values are defined by enumerations in the Interop libraries, these enum names all start with "XL..." and are easy to find with intellisense, in this case:
VB.NET:
row.Find(What:=toFind, LookIn:=Excel.XlFindLookIn.xlValues, LookAt:=Excel.XlLookAt.xlWhole)
I'm using the Excel named import like this:
VB.NET:
Imports Excel = Microsoft.Office.Interop.Excel
 
Back
Top