Macro help for inserting data in spreadsheets!

Status
Not open for further replies.

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I want to create a macro to insert a value in cell "U37", but that value can only be inserted in spreadsheets with the name other than "Potável C1", "Potável C2", "Potável C3.1", and "Potável C3.2"



I know my code is not right but I currently have the following:


VBA Code:
Dim ws, counter As Integer
Dim sh As Worksheet


Public Sub WriteValues()


For Each sh In ThisWorkbook.Worksheets
    If sh.Name <> "Potável C1" Or sh.Name <> "Potável C2" Or sh.Name <> "Potável C3.1" Or sh.Name <> "Potável C3.2" Then
    
        ws = ActiveWorkbook.Sheets.Count

        For counter = 1 To ws
    
        Worksheets(counter).Select
            Range("AC12").Select
            If ActiveCell.Value = "" Then
                With ActiveSheet.Range("AC12:AE12")
                    .Font.Bold = True
                    .Value = Array("Date", "Time", "Value")
                    .HorizontalAlignment = xlRight
                End With
            
            Else
            End If

            Range("AC13").Select
            If ActiveCell.Value = "" Then
                ActiveCell.Value = Range("U13").Value
                Range("AE13").Value = WorksheetFunction.Sum(Range("W13:W108"))
                Range("AF13").Value = "kWh"
            
            Else
            End If

        Next counter
        
    Else
    End If
    
Next
End Sub


Someone can help me?
 

Attachments

  • defsf.JPG
    defsf.JPG
    58.1 KB · Views: 6
  • ficheiros.JPG
    ficheiros.JPG
    21.7 KB · Views: 6

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
the cells mentioned in the code were taken from another code so they are different than the one I mentioned but I just want to know how to insert the values in the spreadsheet where the names are different from the ones I mentioned
 
Upvote 0
Duplicate to: Macro for writing to specific Excel spreadsheets

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread since I have suggested an answer there.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

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