Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code only working up to 9999 rows

I have some VBA code which is activated when anything is input or paste
into the D column of a spreadsheet. It takes out any spaces or dashe
that are in the cells. My problem is that it only works for cell
1-9999. If anything is input in cell 10,000+, the macro isn't run.
Here's my code:

Sub AccountID()
Dim lLastRow As Long
Dim Sh1 As Worksheet, rng As Range

Set Sh1 = ThisWorkbook.Worksheets("Form")
lLastRow = Sh1.Cells(Rows.Count, "D").End(xlUp).Row
Set rng = Sh1.Range("D2", "D2" & lLastRow)

rng.Replace _
What:=" ", Replacement:="", _
searchorder:=xlByRows, MatchCase:=True

rng.Replace _
What:="-", Replacement:="", _
searchorder:=xlByRows, MatchCase:=True

rng.NumberFormat = "General"

Set Sh1 = Nothing
Set rng = Nothing
End Sub



What would be limiting this to 9999 lines?

TIA!
sup19

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA code only working up to 9999 rows

Shouldn't

Set rng = Sh1.Range("D2", "D2" & lLastRow)

be

Set rng = Sh1.Range("D2", "D" & lLastRow)

or

Set rng = Sh1.Range("D2:D" & lLastRow)

--
Regards,
Tom Ogilvy


"sup191 " wrote in message
...
I have some VBA code which is activated when anything is input or pasted
into the D column of a spreadsheet. It takes out any spaces or dashes
that are in the cells. My problem is that it only works for cells
1-9999. If anything is input in cell 10,000+, the macro isn't run.
Here's my code:

Sub AccountID()
Dim lLastRow As Long
Dim Sh1 As Worksheet, rng As Range

Set Sh1 = ThisWorkbook.Worksheets("Form")
lLastRow = Sh1.Cells(Rows.Count, "D").End(xlUp).Row
Set rng = Sh1.Range("D2", "D2" & lLastRow)

rng.Replace _
What:=" ", Replacement:="", _
searchorder:=xlByRows, MatchCase:=True

rng.Replace _
What:="-", Replacement:="", _
searchorder:=xlByRows, MatchCase:=True

rng.NumberFormat = "General"

Set Sh1 = Nothing
Set rng = Nothing
End Sub



What would be limiting this to 9999 lines?

TIA!
sup191


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA code only working up to 9999 rows

Change

Set rng = Sh1.Range("D2", "D2" & lLastRow)
' to
Set rng = Sh1.Range("D2", "D" & lLastRow)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"sup191 " wrote in
message ...
I have some VBA code which is activated when anything is input

or pasted
into the D column of a spreadsheet. It takes out any spaces or

dashes
that are in the cells. My problem is that it only works for

cells
1-9999. If anything is input in cell 10,000+, the macro isn't

run.
Here's my code:

Sub AccountID()
Dim lLastRow As Long
Dim Sh1 As Worksheet, rng As Range

Set Sh1 = ThisWorkbook.Worksheets("Form")
lLastRow = Sh1.Cells(Rows.Count, "D").End(xlUp).Row
Set rng = Sh1.Range("D2", "D2" & lLastRow)

rng.Replace _
What:=" ", Replacement:="", _
searchorder:=xlByRows, MatchCase:=True

rng.Replace _
What:="-", Replacement:="", _
searchorder:=xlByRows, MatchCase:=True

rng.NumberFormat = "General"

Set Sh1 = Nothing
Set rng = Nothing
End Sub



What would be limiting this to 9999 lines?

TIA!
sup191


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code only working up to 9999 rows

Thanks guys!! The "D2" to "D" fixed it. I needed to omit cell D1 as i
was the header to the column and I didn't want it to be effected by th
macro. Now I see why it should just be "D".

My eyes are opened a little wider... :)




sup19

--
Message posted from http://www.ExcelForum.com



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code Not Working tictox Excel Discussion (Misc queries) 3 October 25th 10 04:25 PM
Adding Rows offsets to working rows across two worksheets tom Setting up and Configuration of Excel 3 July 30th 06 07:54 PM
add time greater than 9999:56 PapaT Excel Worksheet Functions 2 March 28th 06 03:48 AM
why this code not working tj Excel Programming 0 September 2nd 03 07:14 PM
why this code not working Bernie Deitrick[_2_] Excel Programming 0 September 2nd 03 05:08 PM


All times are GMT +1. The time now is 09:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"