URL clean

Kamranas

Banned User
Joined
Feb 25, 2023
Messages
53
Office Version
  1. 2016
Platform
  1. Windows
I need an excel VBA code that removes the following from my URL Column B, I need a dynamic range code, not a static range.
1 http://www.
2 https://www.
3 http://
4 https://
5 www.

more details
need an excel VBA code that removes from my URL
1 http://www.
2 https://www.
3 http://
4 https://
5 www.
use find and replace empty but the condition is this i need dynamic range.
 

Attachments

  • url clean.PNG
    url clean.PNG
    35.1 KB · Views: 7

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi Kamranas,

Take a look at this code and see if it does what you want. Make a backup of your worksheet just in case, as actions done through VBA cannot be undone.

VBA Code:
Sub RemoveURLPrefixes()
    Dim LastRow As Long
    Dim i As Long
    Dim URL As String
    Dim Prefixes() As String
    
    ' Define the prefixes to remove
    Prefixes = Split("http://www.,https://www.,http://,https://,www.", ",")
    
    ' Get the last used row in column B
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
    
    ' Loop through each cell in column B
    For i = 1 To LastRow
        ' Get the URL from the cell
        URL = Cells(i, "B").Value
        
        ' Remove the prefixes from the URL
        For Each Prefix In Prefixes
            If InStr(URL, Prefix) = 1 Then
                URL = Mid(URL, Len(Prefix) + 1)
            End If
        Next Prefix
        
        ' Update the cell with the cleaned URL
        Cells(i, "B").Value = URL
    Next i
End Sub
 
Upvote 1
Solution
How about
VBA Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
For r = lr To 1 Step -1
If InStr(Cells(r, 2), "https://www.") Then Cells(r, 2) = Replace(Cells(r, 2), "https://www.", "")
Next r
End Sub
 
Upvote 1
Which code are you referring to ?
 
Upvote 0
Hi Kamranas,

Take a look at this code and see if it does what you want. Make a backup of your worksheet just in case, as actions done through VBA cannot be undone.

VBA Code:
Sub RemoveURLPrefixes()
    Dim LastRow As Long
    Dim i As Long
    Dim URL As String
    Dim Prefixes() As String
   
    ' Define the prefixes to remove
    Prefixes = Split("http://www.,https://www.,http://,https://,www.", ",")
   
    ' Get the last used row in column B
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
   
    ' Loop through each cell in column B
    For i = 1 To LastRow
        ' Get the URL from the cell
        URL = Cells(i, "B").Value
       
        ' Remove the prefixes from the URL
        For Each Prefix In Prefixes
            If InStr(URL, Prefix) = 1 Then
                URL = Mid(URL, Len(Prefix) + 1)
            End If
        Next Prefix
       
        ' Update the cell with the cleaned URL
        Cells(i, "B").Value = URL
    Next i
End Sub
Hi Kamranas,

Take a look at this code and see if it does what you want. Make a backup of your worksheet just in case, as actions done through VBA cannot be undone.

VBA Code:
Sub RemoveURLPrefixes()
    Dim LastRow As Long
    Dim i As Long
    Dim URL As String
    Dim Prefixes() As String
   
    ' Define the prefixes to remove
    Prefixes = Split("http://www.,https://www.,http://,https://,www.", ",")
   
    ' Get the last used row in column B
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
   
    ' Loop through each cell in column B
    For i = 1 To LastRow
        ' Get the URL from the cell
        URL = Cells(i, "B").Value
       
        ' Remove the prefixes from the URL
        For Each Prefix In Prefixes
            If InStr(URL, Prefix) = 1 Then
                URL = Mid(URL, Len(Prefix) + 1)
            End If
        Next Prefix
       
        ' Update the cell with the cleaned URL
        Cells(i, "B").Value = URL
    Next i
End Sub
Thank you so much
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,227
Members
449,303
Latest member
grantrob

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