Assistance needed - Please be gentle

montypython

New Member
Joined
Apr 1, 2014
Messages
12
Hi Some advice needed

Is there wa way to optimise these macro's I am still learning so please bare with me

Dim dateRange As Range
Set dateRange = Range("A2:H" & Cells(Rows.Count, "H").End(xlUp).Row)

If Application.CountIf(dateRange, "") = 0 And Application.CountIf(dateRange, "=ISNUMBER(value)") = dateRange.Cells.Count Then
Range("I2:I" & lastRow).FormulaR1C1 = "=INT(RC[-7]-RC[-2])"
End If



Sub FormatColumnI()
Dim lastRow As Long

' Determine the last row of data
lastRow = Cells(Rows.Count, 1).End(xlUp).Row

' Set the number format for cells in Column I
Range("I2:I" & lastRow).NumberFormat = "0"
End Sub

Sub CalculateDaysDifference()
Dim lastRow As Long
Dim i As Long

lastRow = Cells(Rows.Count, "A").End(xlUp).Row 'Get last row in column A

For i = 1 To lastRow 'Loop through each row in column A
If IsDate(Cells(i, "A").Value) And IsDate(Cells(i, "H").Value) Then 'Check if both values in columns A and H are dates
Cells(i, "I").Value = DateDiff("d", Cells(i, "A").Value, Cells(i, "H").Value) 'Calculate the number of days between the two dates and put the result in column I
End If
Next i
End Sub




Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("I:I")) Is Nothing Then
Call CalculateDaysDifference
End If
End Sub

on the last one I am getting a compile error, I need it to run the macro live when updating in my worksheet or perhaps a suggestion for another solution


Thanks Keith
 

Attachments

  • 2023-02-24 12_51_28-Charlene.xlsm - Excel.jpg
    2023-02-24 12_51_28-Charlene.xlsm - Excel.jpg
    75.8 KB · Views: 6
I think at this rate its going to be better to start the sheet from scratch, things were going well and then sheet started going horrible wrong, I really thought I was doing well. It was a table but the desired effect got lost along the way, I just can't have the data capturer changing any formulas thats one of the reasons I also went for pivot slicers. I will get there at my age my brain needs stimulating but today was not a good day for brain stimulation
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi there

Any idea why this is happening, it is not showing the worksheet to run the macro, I have the Column A populating perfectly but when I try and run my next macro to work out the days and populate automatically, this is what pops up?

Cheers

Keith
 

Attachments

  • macro problem.jpg
    macro problem.jpg
    58 KB · Views: 5
Upvote 0
I lost you on the previous message: did you decide to restart your workbook from zero or what?

As far as your problem with starting the macro, well it seems there is no any macro available to be started. Which Subs are in your vba project, and in which vba module are they hosted? (the name displayed in the window header, thus "Sheet1(Code)", in the image you attached)
 
Upvote 0
I lost you on the previous message: did you decide to restart your workbook from zero or what?

As far as your problem with starting the macro, well it seems there is no any macro available to be started. Which Subs are in your vba project, and in which vba module are they hosted? (the name displayed in the window header, thus "Sheet1(Code)", in the image you attached)
I have been trying over again just to see
 
Upvote 0
Bellrossview - Keith verson 1.xlsm
ABCDEFGHIJK
1Date Logged onto spreadsheet DescriptionStreet AddressSuburbNameContact NoAdditional info or refDate reported to MunicpalityDays OutstandingStatusComment
225/02/2023 09:03Street Light20 Bertie Blogs StreetSeaviewJoe Ordinary083 594 2851F/912151223/02/2022367
325/02/2023 09:03Pothole21 Pluto StreetSeaviewDaffy Duck031 555 5555F/912151301/02/2022389
425/02/2023 09:25Street Light61 Fast Car StreetBellairJim Bob031 123 1234F/912151401/03/2021726
525/02/2023 09:26Sewerage 12 I don't know StreetRossburghBobby Burger087 444 4444F/912151505/07/20191331
625/02/2023 09:42Pothole13 Pothole StreetBellairTina Turner111 111 1111F/912151622/09/2022156
725/02/2023 10:31Burst Pipe9 Downing SteetSeaviewBob Geldorf222 222 2222F/912151721/05/20143202
825/02/2023 10:31Street LightThe WhithouseBellairPotis333 333 3333F/912151831/12/20171882
Data Sheet
Cells with Data Validation
CellAllowCriteria
D1:D8List='List Sheet'!$A$2:$A$4
B1List='List Sheet'!$C$2:$C$5
B2:B1048576List='List Sheet'!$C$2:$C$6
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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