Question : Copy cell value into a range in VBA

I will have about 180 worksheet and for each one, I need to take the first six characters in cell A2 and paste it into four range of cells in column H.  The code runs down to the section to do the copy/paste but it keep giving me "Run-time error '1004'  Application-defined or object-defined error.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
Public Sub DataRanges()
'Sets the data ranges for the data sources, copies the account number into
'associated column
Dim rngchar As Range, rngCharAcct As Range, rngTop10 As Range, rngTop10Acct As Range
Dim rnggics As Range, rnggicsAcct As Range, rngCountry As Range, rngCountryAcct As Range
Dim rngSecurities As Range, rngCheck As Range, wks As Worksheet
Dim strAccount As String

For Each wks In Worksheets
If wks.Name Like "MySheet_*" Then
        wks.Activate
        strAccount = CStr(Left(wks.Range("A2").Value, 6))
        Set rngchar = wks.Range("C11:G15")
        Set rngCharAcct = wks.Range("H11:H15")
        Set rngTop10 = wks.Range("C35:F44")
        Set rngTop10Acct = wks.Range("H356:H44")
        Set rnggics = wks.Range("A68:D77")
        Set rnggicsAcct = wks.Range("H68:H77")
        Set rngSecurities = wks.Range("C16:E16")
        Set rngCheck = Cells(Rows.Count, "E").End(xlUp).Offset(-1, -1)
    
            If rngCheck.Value <= 5 Then
                Set rngCountry = Range(Cells(98, "A"), Cells(Rows.Count, "E").End(xlUp).Offset(-2, 0))
                Set rngCountryAcct = Range(Cells(98, "H"), Cells(Rows.Count, "E").End(xlUp).Offset(-2, 3))
            Else
                Set rngCountry = Range(Cells(98, "A"), Cells(Rows.Count, "E").End(xlUp).Offset(-1, 0))
                Set rngCountryAcct = Range(Cells(98, "H"), Cells(Rows.Count, "E").End(xlUp).Offset(-1, 3))
            End If

'Copy account number to selection ranges in column H
'ERRORS OUT HERE!
        wks.Range(rngCharAcct).Select
        ActiveSheet.Paste (strAccount)
        wks.Range(rngTop10Acct).Select
        ActiveSheet.Paste (strAccount)
        wks.Range(rnggicsAcct).Select
        ActiveSheet.Paste (strAccount)
        wks.Range(rngCountryAcct).Select
        ActiveSheet.Paste (strAccount)
    End If
         
Next

End Sub

Answer : Copy cell value into a range in VBA

then one way to do it is
'define this new variable
Dim rngCell as Range

For Each rngCell in rngCharAcct
  rngCell = strAccount
Next
Random Solutions  
 
programming4us programming4us