I am trying to see if I can use the column header name "What Fruit" instead of like "E"?
Here is a part of my code that I am changing about 15 times but I want to be able to add columns to my sheet with out Messing up my VBA code.
Range("d5").Select
With ActiveSheet
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
End With
Do Until ActiveCell.Row > LastRow
FRUIT= UCase(Trim(Trim(Range("E" & ActiveCell.Row))))
sqlstatement = " " & _
" SELECT Apple FROM TableName" & _
"WHERE ITEM IN ('" & FRUIT & "')"
Set rstRecordset = New ADODB.Recordset
rstRecordset.Open _
Source:=" " & sqlstatement & " ", _
ActiveConnection:=cnnConnect, _
CursorType:=adOpenForwardOnly
On Error Resume Next
SomeVarible = rstRecordset.Fields("Apple").Value
If SomeVarible = 0 Then
GoTo NextItem6
Else
End If
ActiveCell.CopyFromRecordset rstRecordset
NextItem:
ActiveCell.Offset(1, 0).Select
Loop
Here is a part of my code that I am changing about 15 times but I want to be able to add columns to my sheet with out Messing up my VBA code.
Range("d5").Select
With ActiveSheet
LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
End With
Do Until ActiveCell.Row > LastRow
FRUIT= UCase(Trim(Trim(Range("E" & ActiveCell.Row))))
sqlstatement = " " & _
" SELECT Apple FROM TableName" & _
"WHERE ITEM IN ('" & FRUIT & "')"
Set rstRecordset = New ADODB.Recordset
rstRecordset.Open _
Source:=" " & sqlstatement & " ", _
ActiveConnection:=cnnConnect, _
CursorType:=adOpenForwardOnly
On Error Resume Next
SomeVarible = rstRecordset.Fields("Apple").Value
If SomeVarible = 0 Then
GoTo NextItem6
Else
End If
ActiveCell.CopyFromRecordset rstRecordset
NextItem:
ActiveCell.Offset(1, 0).Select
Loop