jack777531
New Member
- Joined
- Dec 20, 2023
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
hi there
i am using range() function in my macro with loop for next .
part one of this macro the one take most almost 90% of time in this macro .
Calculation in part 1 will happened after copying and pasting the new value as input .
i have few questions regardsing this .
1-How to improve this macro making it run faster ( i need to keep the calculation part on )?
2-can i turn off calculation before copying pasting then turn on the calculation, then off when i am out of next loop ?
3- which different function can be used in place of range() but still can be looped using for next, example ?
4- origin macro loop next was 148000 ,but due to taking long time i reduce the number for testing .
Thank you
i am using range() function in my macro with loop for next .
part one of this macro the one take most almost 90% of time in this macro .
Calculation in part 1 will happened after copying and pasting the new value as input .
i have few questions regardsing this .
1-How to improve this macro making it run faster ( i need to keep the calculation part on )?
2-can i turn off calculation before copying pasting then turn on the calculation, then off when i am out of next loop ?
3- which different function can be used in place of range() but still can be looped using for next, example ?
4- origin macro loop next was 148000 ,but due to taking long time i reduce the number for testing .
VBA Code:
Sub Macro1()
'part 1
Dim StartTime As Double
Dim MinutesElapsed As String
Dim i As Long
Dim t As Long
Dim a As Long
'Remember time when macro starts
StartTime = Timer
Application.DisplayStatusBar = False
Application.EnableEvents = False
Application.ScreenUpdating = False
ActiveSheet.DisplayPageBreaks = False 'note this is a sheet-level setting
For i = 159 To 2590
'copy row as input
Sheets("MAIN").Select
Range(Cells(i, 2), Cells(i, 12)).Select
Selection.Copy
'select where to paste input
Range("D18").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
'paste here in colume for input
Range("L124").Select
'Apllication.CutCopyMode = False
'After calculation done copy the output
Selection.Copy
'paste the output here
Range("U" & i).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next
'part two
'if you find true copy and paste
For t = 159 To 2590
a = Range("V" & t)
If a = True Then
Range(Cells(t, 2), Cells(t, 12)).Select
Selection.Copy
Range("W112").Select
ActiveSheet.Paste
Else
End If
Next t
'part three
'select the one in part two and copy it to new loction
Range("W112:AG112").Select
Selection.Copy
Range("D18").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Application.CutCopyMode = False
Application.DisplayStatusBar = True
Application.EnableEvents = True
Application.ScreenUpdating = True
ActiveSheet.DisplayPageBreaks = True 'note this is a sheet-level setting
Application.Calculation = xlCalculationAutomatic
'Determine how many seconds code took to run
MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss")
'Notify user in seconds
MsgBox "This code ran successfully in " & MinutesElapsed & " minutes", vbInformation
End Sub
Thank you