I need help to create a VBA code

daniboymu

New Member
Joined
Nov 1, 2020
Messages
39
Office Version
  1. 2019
Platform
  1. Windows
I need help creating a macro which runs these 2 codes at the same time every 5 minutes between 9:05 am to 5:45 pm could someone please help me its very important!
FIRST CODE:
VBA Code:
Sub Atualizar()



Rows(7).Insert

Range("A8:DG8").Value = Range("A5:DG5").Value

End Sub

THE SECOND CODE:
VBA Code:
Sub Atualizar_Correl()

'

' Atualizar_Correl Macro



Range("A7").Select

ActiveCell.FormulaR1C1 = "=Database!R[1]C"

Range("B7").Select

ActiveCell.FormulaR1C1 = _

"=HLOOKUP(R6C2,Database!R6C2:R314C27,ROW(Database!R[1]C)-5,FALSE)"

Range("C7").Select

ActiveCell.FormulaR1C1 = _

"=HLOOKUP(R6C3,Database!R6C2:R319C27,ROW(Database!R[1]C)-5,FALSE)"

Range("A7").Select

Selection.AutoFill Destination:=Range("A7:A257")

Range("A7:A257").Select

Range("B7").Select

Selection.AutoFill Destination:=Range("B7:B257")

Range("B7:B257").Select

Range("C7").Select

Selection.AutoFill Destination:=Range("C7:C257")

Range("C7:C257").Select

End Sub
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,865
.
VBA Code:
Dim TimeToRun

'Sub auto_open()
'    Call ScheduleclrCol                        'uncomment this for code to auto run when sheet is opened
'End Sub

Sub ScheduleclrCol()
    TimeToRun = Now + TimeValue("00:05:00")     '<----- adjust time to fire here  HH:MM:SS
    Application.OnTime TimeToRun, "MacroRun"
End Sub

Sub MacroRun()
    Calculate
   
    Atualizar
    Atualizar_Correl
   
    Call ScheduleclrCol
End Sub

'Sub auto_close()                               'uncomment this for code to auto stop when sheet is closed
'    On Error Resume Next
'    Application.OnTime TimeToRun, "MacroRun, , False"
'End Sub

Sub manual_stop()                               'button click for stop (Manual Stop)
    On Error Resume Next
    Application.OnTime TimeToRun, "MacroRun, , False"
End Sub

Sub Atualizar()

Rows(7).Insert

Range("A8:DG8").Value = Range("A5:DG5").Value

End Sub

Sub Atualizar_Correl()

'

' Atualizar_Correl Macro



Range("A7").Select

ActiveCell.FormulaR1C1 = "=Database!R[1]C"

Range("B7").Select

ActiveCell.FormulaR1C1 = "=HLOOKUP(R6C2,Database!R6C2:R314C27,ROW(Database!R[1]C)-5,FALSE)"

Range("C7").Select

ActiveCell.FormulaR1C1 = "=HLOOKUP(R6C3,Database!R6C2:R319C27,ROW(Database!R[1]C)-5,FALSE)"

Range("A7").Select

Selection.AutoFill Destination:=Range("A7:A257")

Range("A7:A257").Select

Range("B7").Select

Selection.AutoFill Destination:=Range("B7:B257")

Range("B7:B257").Select

Range("C7").Select

Selection.AutoFill Destination:=Range("C7:C257")

Range("C7:C257").Select

End Sub

Create two CommandButtons. One connects to ScheduleclrCol ... the other connects to manual_stop
 

Watch MrExcel Video

Forum statistics

Threads
1,123,454
Messages
5,601,764
Members
414,471
Latest member
cchunyadi

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
Top