Consulting

Results 1 to 15 of 15

Thread: Modify a macro to remove blanks from a worksheet

  1. #1
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location

    Modify a macro to remove blanks from a worksheet

    Hi

    I have a macro that was written for me , however the source of my data has now changed and the macro is not doing what I like it to

    I will appreciate any help in fixing my macro

    Kind regards
    Rajann

    PS The data is copies into a worksheet called Racescrape and after running the macro it creates a worksheet called Racdata which spaces the data after each race

    Now it is not doing that

    It creates Racedata but the spacing is not being maintained
    Attached Files Attached Files

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Replace line
    Set d = .Range("A:A").Find("Race-" & i + 1, LookAt:=xlWhole)
    with
    Set d = .Range("A:A").Find("Race " & i + 1, LookAt:=xlWhole)
    Artik

  3. #3
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location
    Hi Artik

    Thank you for your help

    However it is not spacing the data between races.

    It should have spaces between races in the event there are 1 to twenty horses in the race

    Kind regards

    rajann

  4. #4
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location
    May I post the file that I made changes as per your guidance

    Rajann
    Attached Files Attached Files

  5. #5
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    In the attached file you still have ...Find("Race-" & i + 1... instead of ...Find("Race " & i + 1...

    Artik

  6. #6
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location
    hi Artik

    Many thnx for pointing out my error

    I fixed the first line and forgot to do like wise in second line

    If I may ask

    When the macro executes, the 750 from racescrape on line 1 col B moves to col C in Racedata.

    second question

    will it be possible that
    the worksheet analysis be cleared before data is copied from racedata to analysis

    regards

    Rajann

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    Sub MacroTest()
    Dim c As Range
    Dim d As Range
    Dim i As Integer
        
    Sheets("Analysis").UsedRange.Clear
        
    Application.DisplayAlerts = False
    On Error Resume Next
    Worksheets("RaceData").Delete
    On Error GoTo 0
    Application.DisplayAlerts = True
        
    Worksheets("Racescrape").Copy Before:=Worksheets(1)
        
    With Worksheets(1)
      .Name = "RaceData"
      For i = 1 To 20
        Set c = .Range("A:A").Find("Race " & i, LookAt:=xlWhole)
        c.Offset(1, 0).EntireRow.Delete
        Set d = .Range("A:A").Find("Race " & i + 1, LookAt:=xlWhole)
        If d Is Nothing Then GoTo Finish
        If d.Row - c.Row < 23 Then .Range(d, d.Offset(22 - (d.Row - c.Row))).EntireRow.Insert
        If d.Row - c.Row > 23 Then .Range(d(0), d.Offset(23 - (d.Row - c.Row))).EntireRow.Delete
      Next i
    Finish:
      .Range("A:E").EntireColumn.AutoFit
    End With
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location
    Hi

    Many thanx for your help

    Yes its working fine for which I an grateful for your help

    I created a further sheet and need to fix headings in line , however everytime I run the macro it gets erase.

    I also found that when I run the macro its skips the first line and writes from the second line

    regards
    Attached Files Attached Files
    Last edited by khanaran; 07-30-2019 at 07:58 AM. Reason: add something else

  9. #9
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    Sub MacroTest()
    Dim c As Range
    Dim d As Range
    Dim i As Integer
        
    Sheets("Analysis").UsedRange.Offset(1).Clear
        
    Application.DisplayAlerts = False
    On Error Resume Next
    Worksheets("RaceData").Delete
    On Error GoTo 0
    Application.DisplayAlerts = True
        
    Worksheets("Racescrape").Copy Before:=Worksheets(1)
        
    With Worksheets(1)
      .Name = "RaceData"
      For i = 1 To 20
        Set c = .Range("A:A").Find("Race " & i, LookAt:=xlWhole)
        c.Offset(1, 0).EntireRow.Delete
        Set d = .Range("A:A").Find("Race " & i + 1, LookAt:=xlWhole)
        If d Is Nothing Then GoTo Finish
        If d.Row - c.Row < 23 Then .Range(d, d.Offset(22 - (d.Row - c.Row))).EntireRow.Insert
        If d.Row - c.Row > 23 Then .Range(d(0), d.Offset(23 - (d.Row - c.Row))).EntireRow.Delete
      Next i
    Finish:
      .Range("A:I").EntireColumn.AutoFit
    End With
    Worksheets("Analysis").Range("a2:b1000").Value = Worksheets("Racedata").Range("a1:b1000").Value
    Worksheets("Analysis").Range("c2:f1000").Value = Worksheets("Racedata").Range("d1:g1000").Value
    Worksheets("Analysis").Range("g2:h1000").Value = Worksheets("Racedata").Range("h1:i1000").Value
    Worksheets("Analysis").Range("i2:j1000").Value = Worksheets("Racedata").Range("ab1:ac1000").Value
    Worksheets("Analysis").Range("k2:l1000").Value = Worksheets("Racedata").Range("n1:o1000").Value
    Worksheets("Analysis").Range("s2:t1000").Value = Worksheets("Racedata").Range("ah1:ai1000").Value
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  10. #10
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location
    hi

    Many thanx for the help

    Its working brilliantly and solved my issue

    Kind regards

    rajann

  11. #11
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location
    Hi

    Many thanx for the help

    I tried to add in a formula but its giving me errors

    column J form calculator

    may you please help

    Kind regards

    Rajann
    Attached Files Attached Files

  12. #12
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Don't know what the formula's supposed to do.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  13. #13
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location
    Quote Originally Posted by p45cal View Post
    Don't know what the formula's supposed to do.
    Hi

    many thanx for responding

    The formula in col J is to find the sumtotal of the value in H( which it reads from bf after it matches H and gets a point value from bg) added to I(which it reads from bi after it matches H and gets a point value from bj) added to I.

    It seems to give a error

    it may have something to do with the decimal point but was adviced to use the round function so am doing something wrong


    Trust this may help in you being able to provide a solution

    Kind regards

    rajann

  14. #14
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    A guess:
    Change the cell format of columns BF and BI to 'General'
    Change the values in them to round numbers from 0 to 100.
    In column J, change instances of ROUND(H72,2) to ROUND(H72,0)
    where H72 here is just one example.

    Reminder: It's a guess.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  15. #15
    VBAX Regular
    Joined
    Apr 2017
    Posts
    10
    Location
    hi

    many thanx for your help

    I managed to sort the problem out by making a little change with the formula and its working perfectly

    I however need a little help with a macro to

    sort each race based on a column

    kind regards

    raj

    PS if you would like to see the correction I can upload for you

    REgards

    Rajann

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •