VBA Selection

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,538
Office Version
  1. 2016
Platform
  1. Windows
Hello Friends,

Is there a way to move the selection to the second column of that same row.

Like if the selection (target cell) is lets say column H32 then I would want the code to make the selection to B32 or if the selection (target cell) in on A15 then i would want the code to make the section to B15.

fName = "\\192.168.0.100\itex Share\ITEX\PO" & Range("T5").Value & ".pdf"


In above case the the file name is calling from Range T5. So what I want is that if my selection is anywhere in row # 5 then it should pick the second column i.e. B5.


Regards,

Humayun
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Many ways, here's one:

Code:
    fName = "\\192.168.0.100\itex Share\ITEX\PO" & Cells(Range("T5").Row, "B").Value & ".pdf"
 
Upvote 0
Try this

Code:
fName = "\\192.168.0.100\itex Share\ITEX\PO" & Range("B" & activecell.row).Value & ".pdf"
 
Upvote 0
Hi Eric & Dante

Thanks for the replies... I will surely try your solution

Meanwhile please have a look at this... I searched a bit on the net and found this solution


Code:
 fName = "\\192.168.0.100\itex Share\ITEX\DESIGNS\" & Cells(ActiveCell.Row, 2).Value & ".pdf"

I would like your thoughts on it.. Is there a better way ? working perfect though

Regards,

Humayun
 
Upvote 0
That's essentially the same solution I presented. The only difference is that it uses the value 2 to indicate the column, while I used "B". They work the same, it's largely a matter of preference in this case. Some people might prefer the "B" because that's easier to recognize as a column identifier. But if you want to use a variable instead of a constant, or put it in a loop, using numbers instead of letters is far easier.

Anyway, glad we could help.
 
Upvote 0
They work the same:

Code:
Range([COLOR=#0000ff]"B"[/COLOR] & ActiveCell.row).Value

Cells(ActiveCell.Row, [COLOR=#0000ff]2[/COLOR]).Value

Cells(ActiveCell.Row, [COLOR=#0000ff]"B"[/COLOR]).Value

How to comment Eric is a matter of preference.
I prefer to use Range() because it allows me to use the Intellisense (is the drop down list that appears next to variables in the VBA).
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,124
Members
453,021
Latest member
Justyna P

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