ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Columns other than one selected by macro being erroneously selecte (https://www.excelbanter.com/excel-programming/431239-columns-other-than-one-selected-macro-being-erroneously-selecte.html)

MichaelDavid

Columns other than one selected by macro being erroneously selecte
 
Greetings! I would like to select column H on a worksheet so that I can
search for specified values in Column H. When I click on the column H Header
("H" at the top of the worksheet), all of column H is selected as expected.

I then wrote the following macro to select Column H:

Sub FindCloseDate()

' FindCloseDate Macro

' Keyboard Shortcut: Ctrl+l

Columns("H:H").Select


End Sub

When I execute this macro, all of columns A through O are selected. The
worksheet is somewhat irregular in that I believe it contains some merged
cells. I am not sure how to include the actual worksheet in this post. I
would like some way of simulating, via an Excel macro, the manual selection
of column H on the worksheet such that only column H is selected. Any help or
suggestions will be greatly appreciated.

--

May you have a most blessed day!

Sincerely,

Michael Fitzpatrick


marcus[_3_]

Columns other than one selected by macro being erroneouslyselecte
 
Hi Michael

It would appear that your merged cells run right through column H.
This is why so many columns are selected. Most likely it is at the
headings in ROW 1 where this is happening so, assuming your merged
cells occur in Row 1 the following will highlight all the used cells
from H2 to the bottom of your dataset.

Sub SelColH()
Dim lw As Integer
lw = Range("H" & Rows.Count).End(xlUp).Row
Range("H2:H" & lw).Select
End Sub


If in the middle of your dataset, you have a heap of merged cells that
run through Column H then I suggest you unmerge those cells. You can
almost always replicate the appearance of merged Cells without
merging.

Hope this helps.

Marcus


MichaelDavid

Columns other than one selected by macro being erroneously sel
 
Greetings! Thanks a million! That's it!!!

Columns("H:H").UnMerge
Columns("H:H").Select

With this solution, it matters not what nor where merged cells are.
--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick


"marcus" wrote:

Hi Michael

It would appear that your merged cells run right through column H.
This is why so many columns are selected. Most likely it is at the
headings in ROW 1 where this is happening so, assuming your merged
cells occur in Row 1 the following will highlight all the used cells
from H2 to the bottom of your dataset.

Sub SelColH()
Dim lw As Integer
lw = Range("H" & Rows.Count).End(xlUp).Row
Range("H2:H" & lw).Select
End Sub


If in the middle of your dataset, you have a heap of merged cells that
run through Column H then I suggest you unmerge those cells. You can
almost always replicate the appearance of merged Cells without
merging.

Hope this helps.

Marcus




All times are GMT +1. The time now is 08:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com