Help with Next code

santnok

Board Regular
Joined
Jan 10, 2014
Messages
97
Hi

I'am trying to do this.

Have a spreedsheet that have some columns like this the table under here


[TABLE="width: 861"]
<tbody>[TR]
[TD][TABLE="class: grid, width: 100%"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[TD="align: center"]I[/TD]
[TD="align: center"]J[/TD]
[TD="align: center"]K[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]Date[/TD]
[TD]Finished[/TD]
[TD][/TD]
[TD]Name[/TD]
[TD]Date[/TD]
[TD]Finished[/TD]
[TD][/TD]
[TD]Name[/TD]
[TD]Date[/TD]
[TD]Finished[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Roy[/TD]
[TD]23.4.2018[/TD]
[TD]x[/TD]
[TD][/TD]
[TD]Mette[/TD]
[TD]27.05.2018[/TD]
[TD][/TD]
[TD][/TD]
[TD]Hanne[/TD]
[TD]01.12.2018[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Mette[/TD]
[TD]27.5.2018[/TD]
[TD][/TD]
[TD][/TD]
[TD]Oskar[/TD]
[TD]30.04.2018[/TD]
[TD]x[/TD]
[TD][/TD]
[TD]Helena[/TD]
[TD]18.07.2018[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Cecilie[/TD]
[TD]03.3.2018[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Hans[/TD]
[TD]01.02.2018[/TD]
[TD]x[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Roy[/TD]
[TD]17.5.2018[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I'am trying to get a module in

Private Sub Worksheet_Change(ByVal Target As Range)


End Sub

to do a thing. If someone write a x to column C,G or K it will run this code I have writen (that dont work)

Code:
Dim lastrowc As String
Dim lastC As String
Dim c As Variant




Dim kollone1 As Variant: kollone1 = 3
Dim kollone2 As Variant: kollone2 = 7
Dim kollone3 As Variant: kollone3 = 11
Dim startRad As String: startRad = 3


lastrowc = Cells(Rows.Count, 1).End(xlUp).Row
'lastC = Cells(1, Columns.Count).End(xlToLeft).Column


Dim col1 As Variant


For c = startRad To lastrowc
For col1 = kollone1 To kollone1


    If Cells(c, col1) = "x" Then
        Cells(c, col1) = "X"
        Cells(c, col1).Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 18
        End With
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
   
    End If
Next col1


Dim col2 As Variant


For col2 = kollone2 To kollone2


    If Cells(c, col2) = "x" Then
        Cells(c, col2) = "X"
        Cells(c, col2).Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 18
        End With
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
   
    End If
Next col2


Dim col3 As Variant


For col3 = kollone3 To kollone3


    If Cells(c, col3) = "x" Then
        Cells(c, col3) = "X"
        Cells(c, col3).Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 18
        End With
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
   
    End If
Next col3


Next c




End Sub

But this do not work, I'am also sure that I can write the code so it is not so long?

Hope that someone understand my problem here :-)
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Hi Fluff

Thank you so much for that code, and it worked like charm :-) Have learned somthing new now :-)
You're welcome & thanks for the feedback.
For the future please see post#10
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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