Need solution with array or something like.

Slade

New Member
Joined
Aug 5, 2011
Messages
26
Hi

I have the following code in a macro. What it do is simple. In one column(H) i enter a time manually and in column(I) i have the current time. If H is bigger then I then do nothing if H is smaller than I bring up message box. This all work well but now i need to do it with more than 1000 line and to copy and paste is going to take allot of time that i do have but it will slow the workbook allot. is there a way i can use an array with the line number in the sheet1.range("H*") and sheet1.range("I*") and sheet1.range("J*"), * being the line number.

Code:
Sub Macro1()
    Dim MustTime As Integer
    Dim CurTime As Integer
    Dim CurTimeSt As String
    MustTime = Sheet1.Range("H7")
    MsgBox MustTime
    CurTimeSt = Sheet1.Range("I7").Text
    Sheet1.Range("J7") = Mid(CurTimeSt, 1, 2) & Mid(CurTimeSt, 4, 2)
    CurTime = Sheet1.Range("J7")
    If CurTime > MustTime Then
    MsgBox "Respond to:" + Sheet1.Range("C7")
    End If
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
if you know the ending row

Code:
dim count as long
 
count = 1
 
do until count = 'insert ending row
 
Sheet1.Range("J" & count) = Mid(CurTimeSt, 1, 2) & Mid(CurTimeSt, 4, 2)
'any code you want to insert 
count = count + 1
 
loop

otherwise if its continuos data and you dont know the end.
Code:
dim count as long
dim counta as long
 
count = Range("A2").CurrentRegion.Rows.count
counta = 1
 
do until counta = count
 
Sheet1.Range("J" & counta) = Mid(CurTimeSt, 1, 2) & Mid(CurTimeSt, 4, 2)
'any code you want to insert
counta = counta + 1
loop
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,214
Members
453,151
Latest member
Lizamaison

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