Edit code VBA

sofas

Active Member
Joined
Sep 11, 2022
Messages
468
Office Version
  1. 2019
Platform
  1. Windows
Hello, I want to calculate the sum of the number of cells after there is the value in the cell ("F3")... Exemple if you find the value in ("A80")
Cells are counted from A80 to me A99
smiller and which is squale to CELLE F3

VBA Code:
Sub Count_cells_if()

Dim ws As Worksheet
Set ws = Worksheets("sh1")

ws.Range("a100") = Application.WorksheetFunction.CountIf(ws.Range("a1:a99"), "<=" & ws.Range("f3"))
ws.Range("b100") = Application.WorksheetFunction.CountIf(ws.Range("b1:b99"), "<=" & ws.Range("f3"))
ws.Range("c100") = Application.WorksheetFunction.CountIf(ws.Range("c1:c99"), "<=" & ws.Range("f3"))
ws.Range("d100") = Application.WorksheetFunction.CountIf(ws.Range("d1:d99"), "<=" & ws.Range("f3"))


End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Your code seem to be OK. What is the problem? Do you want to count after where the value first appears?
 
Upvote 0
Like this?

VBA Code:
Sub Count_cells_if()

Dim ws As Worksheet
Set ws = Worksheets("sh1")

ws.Range("a100") = Application.WorksheetFunction.CountIf(ws.Range("a"&Application.WorksheetFunction.Match(Range("f3"),Range("a1:a99"),0)&":a99"), "<=" & ws.Range("f3"))
ws.Range("b100") = Application.WorksheetFunction.CountIf(ws.Range("b"&Application.WorksheetFunction.Match(Range("f3"),Range("b1:b99"),0)&":b99"), "<=" & ws.Range("f3"))
ws.Range("c100") = Application.WorksheetFunction.CountIf(ws.Range("c"&Application.WorksheetFunction.Match(Range("f3"),Range("c1:c99"),0)&":c99"), "<=" & ws.Range("f3"))
ws.Range("d100") = Application.WorksheetFunction.CountIf(ws.Range("d"&Application.WorksheetFunction.Match(Range("f3"),Range("d1:d99"),0)&":d99"), "<=" & ws.Range("f3"))


End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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