+ Reply to Thread
Results 1 to 5 of 5

Modify VBA due to web source code change

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-11-2024
    Location
    Chicago
    MS-Off Ver
    2021
    Posts
    120

    Modify VBA due to web source code change

    I copy and paste data from a web page. They have changed their format again! Can someone please change VBA so that data is arranged in Columns C-I in workbook below? Thanks in advance.

    Option Explicit
    
    Sub sortdata()
    Dim a(), b()
    Dim i As Long, k As Long, lr As Long
    
        lr = Range("A" & Rows.Count).End(xlUp).Row
        
        a = Range("A1:A" & lr).Value
        ReDim b(1 To UBound(a, 1), 1 To 8)
      
        For i = 1 To UBound(a, 1) Step 22
            If a(i, 1) <> "Spread" Then Exit For
            k = k + 1
            b(k, 1) = a(i + 19, 1)
            b(k, 2) = a(i + 3, 1)
            b(k, 3) = a(i + 4, 1)
            b(k, 4) = a(i + 5, 1)
            b(k, 5) = a(i + 6, 1)
            b(k, 6) = a(i + 7, 1)
            b(k, 7) = a(i + 8, 1)
            b(k, 8) = a(i + 9, 1)
            
            k = k + 1
            b(k, 2) = a(i + 10, 1)
            b(k, 3) = a(i + 11, 1)
            b(k, 4) = a(i + 12, 1)
            b(k, 5) = a(i + 13, 1)
            b(k, 6) = a(i + 14, 1)
            b(k, 7) = a(i + 15, 1)
            b(k, 8) = a(i + 16, 1)
        Next
        Range("C2").Resize(k, UBound(b, 2)).Value = b
        Range("C2").Resize(k).NumberFormat = "h:mm AM/PM"
    End Sub
    AnotherMacrosFIX.xlsm

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,250

    Re: Modify VBA due to web source code change

    Try

    Option Explicit
    
    Sub demox()
    Dim a, b
    Dim i As Long, j As Long, n As Long, nx As Long, lr As Long
    
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    a = [A1].Resize(lr, 1)
    nx = Application.CountIf(Columns(1), "Spread")
    ReDim b(1 To nx * 2, 1 To 8)
    
    
    For i = 1 To UBound(a, 1) Step 23
        If a(i, 1) = "Spread" Then
            n = n + 1
            b(n, 2) = a(i + 3, 1):
            For j = 3 To 7
                b(n, j) = a(i + j + 2, 1)
            Next j
            b(n, 1) = a(i + 19, 1)
            n = n + 1
            b(n, 2) = a(i + 10, 1):
            For j = 3 To 7
                b(n, j) = a(i + j + 9, 1)
            Next j
        End If
    Next i
    
    [C2].Resize(n, 8) = b
    Columns(3).NumberFormat = "h:mm AM/PM"
    End Sub
    Last edited by JohnTopley; 07-01-2025 at 02:28 PM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    02-11-2024
    Location
    Chicago
    MS-Off Ver
    2021
    Posts
    120

    Re: Modify VBA due to web source code change

    Quote Originally Posted by JohnTopley View Post
    What is different to your last post on the same subject (to which I replied)?
    The data from the web source is an entirely new set for a different sport.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,250

    Re: Modify VBA due to web source code change

    See update in post #2

  5. #5
    Forum Contributor
    Join Date
    02-11-2024
    Location
    Chicago
    MS-Off Ver
    2021
    Posts
    120

    Re: Modify VBA due to web source code change

    Thanks again, John. Works like a charm!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Modify VBA due to change in format of source web page
    By IdabaMalouki in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-30-2025, 09:13 AM
  2. [SOLVED] Modify the code to consolidate files in same order as saved in source folder
    By Masa1989 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-17-2015, 09:21 AM
  3. Replies: 1
    Last Post: 08-07-2015, 10:47 AM
  4. [SOLVED] How can I modify my current code to not change once populated
    By Dena in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-05-2013, 01:52 PM
  5. [SOLVED] Modify Sparkline to Change Source Data
    By daffodil11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2013, 04:20 PM
  6. change / modify VBA code in other files on the network
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2011, 12:23 PM
  7. Modify code to change Sum Range
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 11-28-2010, 03:32 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1