VBA Get column letter based on cell text and use as string

adinev

New Member
Joined
Nov 10, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I am trying to find a column letter based on a text ,contained in a cell. I managed to find the letter, but the next part is what bothers me. The column letter(declared as "trcol") is a part of a loop that goes through the table and copies certain values based on that column.So that column should be the target column to copy from.This is what i have so far:

VBA Code:
Dim trcol as String
Workbooks.Open (ThisWorkbook.Path & workb)
Sheets(sh).Select
Set Cell = Cells.Find("Customer Score %", , xlValues, xlPart, , , False)
If Not Cell Is Nothing Then

  ColLetter = Split(Cell.Address, "$")(1)
     trcol = """ & ColLetter & """
    
     
Else
  MsgBox "I cannot find that text on this sheet"
End If
''''''''''''''''''''''
'the loop
''''''''''''''''''''''
Dim N As Long, i As Long

Workbooks.Open (ThisWorkbook.Path & workb)
N = Cells(Rows.Count, sccol).End(xlUp).Row


For i = 2 To N
Dim totalRnNum As Integer: totalRnNum = Range("F100").End(xlUp).Row
Dim totalVal As Double: totalVal = Cells(totalRnNum, 6).Value
Cells(i, **trcol**).Copy '''''''here i need to have the result of the search as trcol


Next i
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You can use
VBA Code:
  trcol = Split(cell.Address, "$")(1)
and then
Excel Formula:
Cells(i, trcol).Copy
 
Upvote 0
I am not sure why you are trying to work with the Column Letter when it is simpler to use the column number.
VBA Code:
Dim trcol as Long
trcol = Cell.Column
Cells(i, trcol).Copy
 
Last edited:
Upvote 0
That will copy from the column where "Customer Score %" is found.
 
Upvote 0
Hi all ,used the index instead of letter,works now.Thank you!!
 
Upvote 0
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,223,875
Messages
6,175,117
Members
452,613
Latest member
amorehouse

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