merge 2 codes into 1

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
675
Office Version
  1. 365
Platform
  1. Windows
good evening,

Hi I use this code:-


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.UsedRange.Borders.Weight = xlThick
    Dim FirstRow As Long, LastRow As Long, i As Long
    Application.EnableEvents = False
    With ActiveSheet.UsedRange
        FirstRow = .Row
        LastRow = .SpecialCells(11).Row
    End With
    For i = LastRow To FirstRow Step -1
        If WorksheetFunction.CountA(Rows(i)) = 0 Then Rows(i).Delete
    Next
    Application.EnableEvents = True
   
     
End Sub

How do I include the code below into the above , so they both run as one?

Code:
Sub WrapandFit()
 
    ActiveCell.WrapText = True
    ActiveCell.EntireRow.AutoFit
 
End Sub


MTIA
Trevor3007
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Without testing

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.UsedRange.Borders.Weight = xlThick
    Dim FirstRow As Long, LastRow As Long, i As Long
    Application.EnableEvents = False
    With ActiveSheet.UsedRange
        FirstRow = .Row
        LastRow = .SpecialCells(11).Row
    End With
    For i = LastRow To FirstRow Step -1
        If WorksheetFunction.CountA(Rows(i)) = 0 Then Rows(i).Delete
    Next

    ActiveCell.WrapText = True
    ActiveCell.EntireRow.AutoFit 
    Application.EnableEvents = True  
End Sub
 
Last edited:
Upvote 0
Maybe...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim FirstRow As Long, LastRow As Long, i As Long
    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
    
    Application.EnableEvents = False

    ActiveSheet.UsedRange.Borders.Weight = xlThick
    Target.WrapText = True
    Target.EntireRow.AutoFit

    With ActiveSheet.UsedRange
        FirstRow = .Row
        LastRow = .SpecialCells(11).Row
    End With

    For i = LastRow To FirstRow Step -1
        If WorksheetFunction.CountA(Rows(i)) = 0 Then Rows(i).Delete
    Next

    Application.EnableEvents = True
End Sub
 
Upvote 0
Maybe...

hello mark

Many thanks for your help again. With your help & a bit of 'trail & error' I produced this:-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim FirstRow As Long, LastRow As Long, i As Long
    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
    
    Application.EnableEvents = False

    ActiveSheet.UsedRange.Borders.Weight = xlThick
    Target.WrapText = True
    Target.EntireRow.AutoFit

    With ActiveSheet.UsedRange
        FirstRow = .Row
        LastRow = .SpecialCells(11).Row
    End With

    For i = LastRow To FirstRow Step -1
        If WorksheetFunction.CountA(Rows(i)) = 0 Then Rows(i).Delete
    Next

    Application.EnableEvents = True
End Sub


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.UsedRange.Borders.Weight = xlThick
    Dim FirstRow As Long, LastRow As Long, i As Long
    Application.EnableEvents = False
    With ActiveSheet.UsedRange
        FirstRow = .Row
        LastRow = .SpecialCells(11).Row
    End With
    For i = LastRow To FirstRow Step -1
        If WorksheetFunction.CountA(Rows(i)) = 0 Then Rows(i).Delete
    Next
    Application.EnableEvents = True




If MsgBox("Do you want to saveworksheet?", vbYesNo) = vbYes Then


ActiveWorkbook.SaveAs ("C:\test\testdata_As_At_ " & Format(Now(), "DD-MMM-YYYY hh_mm_ss") & ".xls")


Else


End If


End Sub


I just got to find out how to email it as an attachment using a predefined *oft file...

KR
Trevor
 
Upvote 0
Without testing

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    ActiveSheet.UsedRange.Borders.Weight = xlThick
    Dim FirstRow As Long, LastRow As Long, i As Long
    Application.EnableEvents = False
    With ActiveSheet.UsedRange
        FirstRow = .Row
        LastRow = .SpecialCells(11).Row
    End With
    For i = LastRow To FirstRow Step -1
        If WorksheetFunction.CountA(Rows(i)) = 0 Then Rows(i).Delete
    Next

    ActiveCell.WrapText = TruePCL

    ActiveCell.EntireRow.AutoFit 
    Application.EnableEvents = True  
End Sub


Hello PCL

all works fine , just need to sort how to email it as an attachment using a predefined *.oft template?

KR
Trevor
 
Upvote 0
just need to sort how to email it as an attachment using a predefined *.oft template?

I would suggest to open a new thread it is another topic
After we can merge all codes ...!
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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