VBA column reference

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
Ok, I'm building a little bit of code for users to fill in a little excel form, submit and then it automatically populates another sheet in the workbook.

Where I am falling down at the moment is in referencing the column. I can find the correct place. But the reference is as a number rather than a letter, so I either need to change this, or change the way that I reference the cell to post the value to.

Anyway here is the code at the moment

Code:
Private Sub Submit_Click()
 
Dim wsf         As Worksheet, _
    p           As String, _
    ste         As Range, _
    ste1        As Long, _
    rng         As Range, _
    rng1        As Long
 
Set wsf = Sheets("Fleet")
p = "Week" & wsf.Range("E5")
With Sheets(p).Range("A3:AE3")
Set ste = .Find(wsf.Range("E3"))
ste1 = ste.Column
End With
 
Y = 7
'Do Until Y = 29
On Error Resume Next
With Sheets(p).Range("A1:A200")
Set rng = .Find(wsf.Range("A" & Y))
rng1 = rng.Row
End With
 
MsgBox (ste1 & rng1)
MsgBox (wsf.Range("E" & Y))
'Sheets(p).Range(ste1 & rng1) = wsf.Range("E" & Y)
 
'Y = Y + 2
 
'Loop
 
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Use Cells to refer to a column letter...

Cells(Row#, Column # OR Letter)

Cells(1,1)
Cells(1,"A")
Range("A1")
All the same thing.

If you need to refer to a multi cell range, use

Range(Cells(1,"A"), Cells(10,"A"))
Same as
Range("A1:A10")

If you need to qualify a sheet name using that syntax, you must specify it on the Range and both cells

With Sheets("Sheet1")
.Range(.Cells(1, "A"), .Cells(10,"A"))
End with


Hope that helps.
 
Upvote 0
Maybe try something like:

'Sheets(p).cells(rng1,ste1) = wsf.Range("E" & Y)

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top