Selecting the cells, with contents, in column A?
How do I select the cells, with contents, in column A?
For example,
I might have a list of names
John
Jack
James
and other times a longer list of times,
John
Jack
James
Jimmy
These will always be in cell A1-AX, X being the final row.
For the first example, I would use the code,
Range("A1:A3").Select
For the second,
Range("A1:A4").Select
I would like to use code that automates this regardless of how many in the list.
excel vba
|
show 7 more comments
How do I select the cells, with contents, in column A?
For example,
I might have a list of names
John
Jack
James
and other times a longer list of times,
John
Jack
James
Jimmy
These will always be in cell A1-AX, X being the final row.
For the first example, I would use the code,
Range("A1:A3").Select
For the second,
Range("A1:A4").Select
I would like to use code that automates this regardless of how many in the list.
excel vba
4
Conditional formatting? Will need to see an example of your excel to give you any kind of actual solution
– urdearboy
Nov 12 '18 at 14:45
When I mean highlighting I mean scroll over them ready to drag them down, not actually highlighting the with colour, maybe selecting is a better option.
– Tony Chivers
Nov 12 '18 at 14:46
1
What is your goal after.Select
? Most of the time, this bit of code is mistakenly used as a middle operator that can be completely scrapped. What is the over all goal here?
– urdearboy
Nov 12 '18 at 14:50
1
Something like:Sheet1.Range("A1:A" & Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))).Select
should do the trick. But you probably don't want to.select
if you are going to write more code after this for that selection.
– JNevill
Nov 12 '18 at 14:52
1
Please look up how to find the last row of a column. Then useRange(“A1:A” & LRow).Select
– urdearboy
Nov 12 '18 at 14:52
|
show 7 more comments
How do I select the cells, with contents, in column A?
For example,
I might have a list of names
John
Jack
James
and other times a longer list of times,
John
Jack
James
Jimmy
These will always be in cell A1-AX, X being the final row.
For the first example, I would use the code,
Range("A1:A3").Select
For the second,
Range("A1:A4").Select
I would like to use code that automates this regardless of how many in the list.
excel vba
How do I select the cells, with contents, in column A?
For example,
I might have a list of names
John
Jack
James
and other times a longer list of times,
John
Jack
James
Jimmy
These will always be in cell A1-AX, X being the final row.
For the first example, I would use the code,
Range("A1:A3").Select
For the second,
Range("A1:A4").Select
I would like to use code that automates this regardless of how many in the list.
excel vba
excel vba
edited Dec 9 '18 at 1:40
Community♦
11
11
asked Nov 12 '18 at 14:43
Tony ChiversTony Chivers
987
987
4
Conditional formatting? Will need to see an example of your excel to give you any kind of actual solution
– urdearboy
Nov 12 '18 at 14:45
When I mean highlighting I mean scroll over them ready to drag them down, not actually highlighting the with colour, maybe selecting is a better option.
– Tony Chivers
Nov 12 '18 at 14:46
1
What is your goal after.Select
? Most of the time, this bit of code is mistakenly used as a middle operator that can be completely scrapped. What is the over all goal here?
– urdearboy
Nov 12 '18 at 14:50
1
Something like:Sheet1.Range("A1:A" & Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))).Select
should do the trick. But you probably don't want to.select
if you are going to write more code after this for that selection.
– JNevill
Nov 12 '18 at 14:52
1
Please look up how to find the last row of a column. Then useRange(“A1:A” & LRow).Select
– urdearboy
Nov 12 '18 at 14:52
|
show 7 more comments
4
Conditional formatting? Will need to see an example of your excel to give you any kind of actual solution
– urdearboy
Nov 12 '18 at 14:45
When I mean highlighting I mean scroll over them ready to drag them down, not actually highlighting the with colour, maybe selecting is a better option.
– Tony Chivers
Nov 12 '18 at 14:46
1
What is your goal after.Select
? Most of the time, this bit of code is mistakenly used as a middle operator that can be completely scrapped. What is the over all goal here?
– urdearboy
Nov 12 '18 at 14:50
1
Something like:Sheet1.Range("A1:A" & Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))).Select
should do the trick. But you probably don't want to.select
if you are going to write more code after this for that selection.
– JNevill
Nov 12 '18 at 14:52
1
Please look up how to find the last row of a column. Then useRange(“A1:A” & LRow).Select
– urdearboy
Nov 12 '18 at 14:52
4
4
Conditional formatting? Will need to see an example of your excel to give you any kind of actual solution
– urdearboy
Nov 12 '18 at 14:45
Conditional formatting? Will need to see an example of your excel to give you any kind of actual solution
– urdearboy
Nov 12 '18 at 14:45
When I mean highlighting I mean scroll over them ready to drag them down, not actually highlighting the with colour, maybe selecting is a better option.
– Tony Chivers
Nov 12 '18 at 14:46
When I mean highlighting I mean scroll over them ready to drag them down, not actually highlighting the with colour, maybe selecting is a better option.
– Tony Chivers
Nov 12 '18 at 14:46
1
1
What is your goal after
.Select
? Most of the time, this bit of code is mistakenly used as a middle operator that can be completely scrapped. What is the over all goal here?– urdearboy
Nov 12 '18 at 14:50
What is your goal after
.Select
? Most of the time, this bit of code is mistakenly used as a middle operator that can be completely scrapped. What is the over all goal here?– urdearboy
Nov 12 '18 at 14:50
1
1
Something like:
Sheet1.Range("A1:A" & Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))).Select
should do the trick. But you probably don't want to .select
if you are going to write more code after this for that selection.– JNevill
Nov 12 '18 at 14:52
Something like:
Sheet1.Range("A1:A" & Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))).Select
should do the trick. But you probably don't want to .select
if you are going to write more code after this for that selection.– JNevill
Nov 12 '18 at 14:52
1
1
Please look up how to find the last row of a column. Then use
Range(“A1:A” & LRow).Select
– urdearboy
Nov 12 '18 at 14:52
Please look up how to find the last row of a column. Then use
Range(“A1:A” & LRow).Select
– urdearboy
Nov 12 '18 at 14:52
|
show 7 more comments
4 Answers
4
active
oldest
votes
Edit the sheet name on the 4th line of code (leave quotes there) and then run the code.
Option Explicit
Sub LRow()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") '<=== Edit Sheet Name
Dim LRow As Long
LRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("A1:A" & LRow).Select
End Sub
Works perfect!!!! Thanks
– Tony Chivers
Nov 12 '18 at 15:12
Is there a way for this code to start in cell A2???
– Tony Chivers
Nov 15 '18 at 8:43
1
Just change the 1 to a 2...
– urdearboy
Nov 15 '18 at 14:11
add a comment |
Private strPrevCellAddress As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Excel.Range
If strPrevCellAddress <> "" Then
Range(strPrevCellAddress).Interior.ColorIndex = -4142
End If
Set r = Cells(1, Target.Column)
Set r = r.Resize(r.End(xlDown).Row, 1)
r.Interior.Color = vbRed
strPrevCellAddress = r.Address
End Sub
add a comment |
You need to refer to the Worksheet.UsedRange.Rows property to find the number of rows.
Dim x As String
x = Me.UsedRange.Rows.Count
Me.Range("A1:A" + x).Select
Make sure the sheet in question is active or you will receive application error.
add a comment |
Sub SelectStartToEnd(sheetName as string, Column as string, Optional StartIndex as integer)
Dim StartHere as string
If IsMissing(StartIndex) = False then
StartHere = Column + CStr((1 + StartIndex))
End If
Sheets(sheetName).Range(startHere + ":" + Range(StartHere).SpecialCells(xlCellTypeLastCell).Address).Select
End Sub
This goes over the Pros and cons of most methods.
https://www.excelcampus.com/vba/find-last-row-column-cell/
This just selects C500 when I try and use it
– Tony Chivers
Nov 12 '18 at 15:11
1
updated code. i forget the key portion.
– BanMe
Nov 12 '18 at 19:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264534%2fselecting-the-cells-with-contents-in-column-a%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Edit the sheet name on the 4th line of code (leave quotes there) and then run the code.
Option Explicit
Sub LRow()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") '<=== Edit Sheet Name
Dim LRow As Long
LRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("A1:A" & LRow).Select
End Sub
Works perfect!!!! Thanks
– Tony Chivers
Nov 12 '18 at 15:12
Is there a way for this code to start in cell A2???
– Tony Chivers
Nov 15 '18 at 8:43
1
Just change the 1 to a 2...
– urdearboy
Nov 15 '18 at 14:11
add a comment |
Edit the sheet name on the 4th line of code (leave quotes there) and then run the code.
Option Explicit
Sub LRow()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") '<=== Edit Sheet Name
Dim LRow As Long
LRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("A1:A" & LRow).Select
End Sub
Works perfect!!!! Thanks
– Tony Chivers
Nov 12 '18 at 15:12
Is there a way for this code to start in cell A2???
– Tony Chivers
Nov 15 '18 at 8:43
1
Just change the 1 to a 2...
– urdearboy
Nov 15 '18 at 14:11
add a comment |
Edit the sheet name on the 4th line of code (leave quotes there) and then run the code.
Option Explicit
Sub LRow()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") '<=== Edit Sheet Name
Dim LRow As Long
LRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("A1:A" & LRow).Select
End Sub
Edit the sheet name on the 4th line of code (leave quotes there) and then run the code.
Option Explicit
Sub LRow()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") '<=== Edit Sheet Name
Dim LRow As Long
LRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ws.Range("A1:A" & LRow).Select
End Sub
edited Nov 12 '18 at 15:06
answered Nov 12 '18 at 15:00
urdearboyurdearboy
7,8333731
7,8333731
Works perfect!!!! Thanks
– Tony Chivers
Nov 12 '18 at 15:12
Is there a way for this code to start in cell A2???
– Tony Chivers
Nov 15 '18 at 8:43
1
Just change the 1 to a 2...
– urdearboy
Nov 15 '18 at 14:11
add a comment |
Works perfect!!!! Thanks
– Tony Chivers
Nov 12 '18 at 15:12
Is there a way for this code to start in cell A2???
– Tony Chivers
Nov 15 '18 at 8:43
1
Just change the 1 to a 2...
– urdearboy
Nov 15 '18 at 14:11
Works perfect!!!! Thanks
– Tony Chivers
Nov 12 '18 at 15:12
Works perfect!!!! Thanks
– Tony Chivers
Nov 12 '18 at 15:12
Is there a way for this code to start in cell A2???
– Tony Chivers
Nov 15 '18 at 8:43
Is there a way for this code to start in cell A2???
– Tony Chivers
Nov 15 '18 at 8:43
1
1
Just change the 1 to a 2...
– urdearboy
Nov 15 '18 at 14:11
Just change the 1 to a 2...
– urdearboy
Nov 15 '18 at 14:11
add a comment |
Private strPrevCellAddress As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Excel.Range
If strPrevCellAddress <> "" Then
Range(strPrevCellAddress).Interior.ColorIndex = -4142
End If
Set r = Cells(1, Target.Column)
Set r = r.Resize(r.End(xlDown).Row, 1)
r.Interior.Color = vbRed
strPrevCellAddress = r.Address
End Sub
add a comment |
Private strPrevCellAddress As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Excel.Range
If strPrevCellAddress <> "" Then
Range(strPrevCellAddress).Interior.ColorIndex = -4142
End If
Set r = Cells(1, Target.Column)
Set r = r.Resize(r.End(xlDown).Row, 1)
r.Interior.Color = vbRed
strPrevCellAddress = r.Address
End Sub
add a comment |
Private strPrevCellAddress As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Excel.Range
If strPrevCellAddress <> "" Then
Range(strPrevCellAddress).Interior.ColorIndex = -4142
End If
Set r = Cells(1, Target.Column)
Set r = r.Resize(r.End(xlDown).Row, 1)
r.Interior.Color = vbRed
strPrevCellAddress = r.Address
End Sub
Private strPrevCellAddress As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Excel.Range
If strPrevCellAddress <> "" Then
Range(strPrevCellAddress).Interior.ColorIndex = -4142
End If
Set r = Cells(1, Target.Column)
Set r = r.Resize(r.End(xlDown).Row, 1)
r.Interior.Color = vbRed
strPrevCellAddress = r.Address
End Sub
answered Nov 12 '18 at 14:56
Nathan_SavNathan_Sav
6,2361619
6,2361619
add a comment |
add a comment |
You need to refer to the Worksheet.UsedRange.Rows property to find the number of rows.
Dim x As String
x = Me.UsedRange.Rows.Count
Me.Range("A1:A" + x).Select
Make sure the sheet in question is active or you will receive application error.
add a comment |
You need to refer to the Worksheet.UsedRange.Rows property to find the number of rows.
Dim x As String
x = Me.UsedRange.Rows.Count
Me.Range("A1:A" + x).Select
Make sure the sheet in question is active or you will receive application error.
add a comment |
You need to refer to the Worksheet.UsedRange.Rows property to find the number of rows.
Dim x As String
x = Me.UsedRange.Rows.Count
Me.Range("A1:A" + x).Select
Make sure the sheet in question is active or you will receive application error.
You need to refer to the Worksheet.UsedRange.Rows property to find the number of rows.
Dim x As String
x = Me.UsedRange.Rows.Count
Me.Range("A1:A" + x).Select
Make sure the sheet in question is active or you will receive application error.
answered Nov 12 '18 at 14:58
AllumearzAllumearz
1896
1896
add a comment |
add a comment |
Sub SelectStartToEnd(sheetName as string, Column as string, Optional StartIndex as integer)
Dim StartHere as string
If IsMissing(StartIndex) = False then
StartHere = Column + CStr((1 + StartIndex))
End If
Sheets(sheetName).Range(startHere + ":" + Range(StartHere).SpecialCells(xlCellTypeLastCell).Address).Select
End Sub
This goes over the Pros and cons of most methods.
https://www.excelcampus.com/vba/find-last-row-column-cell/
This just selects C500 when I try and use it
– Tony Chivers
Nov 12 '18 at 15:11
1
updated code. i forget the key portion.
– BanMe
Nov 12 '18 at 19:10
add a comment |
Sub SelectStartToEnd(sheetName as string, Column as string, Optional StartIndex as integer)
Dim StartHere as string
If IsMissing(StartIndex) = False then
StartHere = Column + CStr((1 + StartIndex))
End If
Sheets(sheetName).Range(startHere + ":" + Range(StartHere).SpecialCells(xlCellTypeLastCell).Address).Select
End Sub
This goes over the Pros and cons of most methods.
https://www.excelcampus.com/vba/find-last-row-column-cell/
This just selects C500 when I try and use it
– Tony Chivers
Nov 12 '18 at 15:11
1
updated code. i forget the key portion.
– BanMe
Nov 12 '18 at 19:10
add a comment |
Sub SelectStartToEnd(sheetName as string, Column as string, Optional StartIndex as integer)
Dim StartHere as string
If IsMissing(StartIndex) = False then
StartHere = Column + CStr((1 + StartIndex))
End If
Sheets(sheetName).Range(startHere + ":" + Range(StartHere).SpecialCells(xlCellTypeLastCell).Address).Select
End Sub
This goes over the Pros and cons of most methods.
https://www.excelcampus.com/vba/find-last-row-column-cell/
Sub SelectStartToEnd(sheetName as string, Column as string, Optional StartIndex as integer)
Dim StartHere as string
If IsMissing(StartIndex) = False then
StartHere = Column + CStr((1 + StartIndex))
End If
Sheets(sheetName).Range(startHere + ":" + Range(StartHere).SpecialCells(xlCellTypeLastCell).Address).Select
End Sub
This goes over the Pros and cons of most methods.
https://www.excelcampus.com/vba/find-last-row-column-cell/
edited Nov 30 '18 at 3:24
answered Nov 12 '18 at 15:00
BanMeBanMe
315
315
This just selects C500 when I try and use it
– Tony Chivers
Nov 12 '18 at 15:11
1
updated code. i forget the key portion.
– BanMe
Nov 12 '18 at 19:10
add a comment |
This just selects C500 when I try and use it
– Tony Chivers
Nov 12 '18 at 15:11
1
updated code. i forget the key portion.
– BanMe
Nov 12 '18 at 19:10
This just selects C500 when I try and use it
– Tony Chivers
Nov 12 '18 at 15:11
This just selects C500 when I try and use it
– Tony Chivers
Nov 12 '18 at 15:11
1
1
updated code. i forget the key portion.
– BanMe
Nov 12 '18 at 19:10
updated code. i forget the key portion.
– BanMe
Nov 12 '18 at 19:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264534%2fselecting-the-cells-with-contents-in-column-a%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Conditional formatting? Will need to see an example of your excel to give you any kind of actual solution
– urdearboy
Nov 12 '18 at 14:45
When I mean highlighting I mean scroll over them ready to drag them down, not actually highlighting the with colour, maybe selecting is a better option.
– Tony Chivers
Nov 12 '18 at 14:46
1
What is your goal after
.Select
? Most of the time, this bit of code is mistakenly used as a middle operator that can be completely scrapped. What is the over all goal here?– urdearboy
Nov 12 '18 at 14:50
1
Something like:
Sheet1.Range("A1:A" & Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))).Select
should do the trick. But you probably don't want to.select
if you are going to write more code after this for that selection.– JNevill
Nov 12 '18 at 14:52
1
Please look up how to find the last row of a column. Then use
Range(“A1:A” & LRow).Select
– urdearboy
Nov 12 '18 at 14:52