How do I activate a macro on one worsheet by inputing a date in another?

boudjamr

New Member
Joined
Apr 1, 2013
Messages
19
Ok, I have a worksheet(worksheet ABC) that I copy data into from an external source (website), in order to get a Vlookup to work I'm using a Trim macro. It works fine if I manually run it, but I'd like to activate it by entering a date in a seperate worksheet (worksheet Exam date). I've tried a couple of suggestions from other posts, but so far nothing...... I don't have much experience with VB, macros, etc.......so any help would be greatly appreciated.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Ok, I have a worksheet(worksheet ABC) that I copy data into from an external source (website), in order to get a Vlookup to work I'm using a Trim macro. It works fine if I manually run it, but I'd like to activate it by entering a date in a seperate worksheet (worksheet Exam date). I've tried a couple of suggestions from other posts, but so far nothing...... I don't have much experience with VB, macros, etc.......so any help would be greatly appreciated.

If you would copy the macro and post it, it would be much easier to give you a good solution. Also, include information about where the macro is stored, i.e. Module1, Sheet1 code module, etc.
 
Upvote 0
This is the macro.......it is located on Sheet3 (code module) of my workbook.........I would like to be able to import data to Sheet3 and have the macro activated once a date is entered on Sheet4.

Sub TrimVisible2()
Dim s As Long, R1 As Range, c As Range
s = Application.Calculation
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
On Error Resume Next
Set R1 = ActiveSheet.UsedRange.SpecialCells(xlConstants, xlTextValues).SpecialCells(xlCellTypeVisible)
R1.Replace What:=Chr(160), Replacement:=Chr(32), LookAt:=xlPart
For Each c In R1
c.Value = Application.WorksheetFunction.Trim(c.Value)
Next c
Application.ScreenUpdating = True
Application.Calculation = s
End Sub
 
Last edited:
Upvote 0
Copy the Macro below to the standard code module1. Access that code module by pressing Alt+F11.
Code:
Sub TrimVisible2()
Dim R1 As Range, c As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
On Error Resume Next
Set R1 = Sheets("Sheet3").UsedRange.SpecialCells(xlConstants, xlTextValues).SpecialCells(xlCellTypeVisible)
R1.Replace What:=Chr(160), Replacement:=Chr(32), LookAt:=xlPart
 For Each c In R1
  c.Value = Application.WorksheetFunction.Trim(c.Value)
 Next c
On Error GoTo 0
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Then copy this macro to the Sheet4 code module. Access sheet code module by right click sheet name tab, then click view code in the pop up menu. Since you did not specify where the date would be entered on Sheet4, the code below uses column A. You will need to change that part of the code to make it the correct entry location.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A:A")) Is Nothing Then 'Edit date entry range here
    If Not IsDate(Target.Value) Then
        MsgBox "Date Entry Required"
        Exit Sub
    End If
    TrimVisible2
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,559
Members
449,089
Latest member
Motoracer88

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