Помогаю со студенческими работами здесь
Выделить диапазон заполненных ячеек
Добрый день.
помогите пожалуйста сообразить:
как мне выделить диапазон заполненных ячеек в…
Подсчет заполненных ячеек Excel
Здравствуйте!
Достаточно давно столкнулся с проблемой подсчета заполненных ячеек экселя, которую…
Задать максимальное количество заполненных ячеек в строке
Как задать свое количество заполненных ячеек в строке, чтобы заполнение ячеек символами…
Определить количество заполненных ячеек в строке Excel
Подскажите пожалуйста.
Есть код который определяет количество заполненных строк на листе:…
Функция ЕСЛИ только для заполненных ячеек
Всем доброго времени суток!
Необходимо было сделать систему коэффициентов для моей таблицы, но…
Подсчет заполненных и пустых ячеек в столбце DataGridview
Всем привет!
Подскажите как правильно подсчитать кол-во пустых и не пустых ячеек в столбце.
Dim…
Искать еще темы с ответами
Или воспользуйтесь поиском по форуму:
Формулировка задачи:
Добрый день.
помогите пожалуйста сообразить:
как мне выделить диапазон заполненных ячеек в колонке 1:
определяет первую заполненную ячейку:
Определяет последнюю заполненную ячейку:
как это совместить и выделить диапазон от первой заполненной ячейки до последней заполненной
пробовал через переменную, но возможно не так что-то прописывал.. (болею, голова совсем уже не варит ))
Код к задаче: «Выделить диапазон заполненных ячеек»
textual
Range(("A1"), Range("A1").End(xlDown)).Select
Полезно ли:
15 голосов , оценка 4.133 из 5
Выделить диапазон с выделенной ячейки до последней заполнен. |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
I’m just beginning to dive into VBA and I’ve hit a bit of a roadblock.
I have a sheet with 50+ columns, 900+ rows of data. I need to reformat about 10 of those columns and stick them in a new workbook.
How do I programmatically select every non-blank cell in a column of book1, run it through some functions, and drop the results in book2?
asked May 4, 2009 at 18:47
Tyler RashTyler Rash
1,1651 gold badge8 silver badges18 bronze badges
2
I know I’m am very late on this, but here some usefull samples:
'select the used cells in column 3 of worksheet wks
wks.columns(3).SpecialCells(xlCellTypeConstants).Select
or
'change all formulas in col 3 to values
with sheet1.columns(3).SpecialCells(xlCellTypeFormulas)
.value = .value
end with
To find the last used row in column, never rely on LastCell, which is unreliable (it is not reset after deleting data). Instead, I use someting like
lngLast = cells(rows.count,3).end(xlUp).row
answered Sep 26, 2009 at 11:14
iDevlopiDevlop
24.6k11 gold badges89 silver badges147 bronze badges
The following VBA code should get you started. It will copy all of the data in the original workbook to a new workbook, but it will have added 1 to each value, and all blank cells will have been ignored.
Option Explicit
Public Sub exportDataToNewBook()
Dim rowIndex As Integer
Dim colIndex As Integer
Dim dataRange As Range
Dim thisBook As Workbook
Dim newBook As Workbook
Dim newRow As Integer
Dim temp
'// set your data range here
Set dataRange = Sheet1.Range("A1:B100")
'// create a new workbook
Set newBook = Excel.Workbooks.Add
'// loop through the data in book1, one column at a time
For colIndex = 1 To dataRange.Columns.Count
newRow = 0
For rowIndex = 1 To dataRange.Rows.Count
With dataRange.Cells(rowIndex, colIndex)
'// ignore empty cells
If .value <> "" Then
newRow = newRow + 1
temp = doSomethingWith(.value)
newBook.ActiveSheet.Cells(newRow, colIndex).value = temp
End If
End With
Next rowIndex
Next colIndex
End Sub
Private Function doSomethingWith(aValue)
'// This is where you would compute a different value
'// for use in the new workbook
'// In this example, I simply add one to it.
aValue = aValue + 1
doSomethingWith = aValue
End Function
answered May 4, 2009 at 19:43
e.Jamese.James
116k40 gold badges177 silver badges214 bronze badges
1
If you are looking for the last row of a column, use:
Sub SelectFirstColumn()
SelectEntireColumn (1)
End Sub
Sub SelectSecondColumn()
SelectEntireColumn (2)
End Sub
Sub SelectEntireColumn(columnNumber)
Dim LastRow
Sheets("sheet1").Select
LastRow = ActiveSheet.Columns(columnNumber).SpecialCells(xlLastCell).Row
ActiveSheet.Range(Cells(1, columnNumber), Cells(LastRow, columnNumber)).Select
End Sub
Other commands you will need to get familiar with are copy and paste commands:
Sub CopyOneToTwo()
SelectEntireColumn (1)
Selection.Copy
Sheets("sheet1").Select
ActiveSheet.Range("B1").PasteSpecial Paste:=xlPasteValues
End Sub
Finally, you can reference worksheets in other workbooks by using the following syntax:
Dim book2
Set book2 = Workbooks.Open("C:book2.xls")
book2.Worksheets("sheet1")
answered May 4, 2009 at 19:18
Jason WilliamsJason Williams
1,2732 gold badges11 silver badges31 bronze badges
For me the best way to proceed was to:
- Create a new Excel Table
AutoFilter
it by the parameterCriterial:="<>"
An example of the code would be:
Sub ExampleFilterCol()
' Create a Table
Dim ws As Worksheet
Dim rg As Range
Set ws = ActiveSheet
Set rg = ws.Range("A1").CurrentRegion
ws.ListObjects.Add(xlSrcRange, rg, , xlYes).Name = "myNonRepeatedTableName"
' Filter the created table
Dim Io As ListObject
Dim iCol As Long
' Set reference to the first Table on the sheet
' That should be the recently created one
Set lo = Sheets("Totalinfo").ListObjects(1)
' Set filter field
iCol = lo.ListColumns("yourColumnNameToFilter").Index
' Non-blank cells – use NOT operator <>
lo.Range.AutoFilter Field:=iCol, Criteria1:="<>"
End Sub
answered Jun 12, 2022 at 14:23
marinovikmarinovik
2464 silver badges11 bronze badges
This might be completely off base, but can’t you just copy the whole column into a new spreadsheet and then sort the column? I’m assuming that you don’t need to maintain the order integrity.
answered May 12, 2009 at 2:19
Dayton BrownDayton Brown
1,2283 gold badges16 silver badges31 bronze badges
0
Выделения относительно активной ячейки
Выделить вниз до первой или последней заполненной ячейки (равносильно нажатию Ctrl+Shift+Down)
Sub CtrlShiftDown()
Range(ActiveCell, ActiveCell.End(xlDown)).Select
End Sub
Выделить вверх до первой или последней заполненной ячейки (равносильно нажатию Ctrl+Shift+Up)
Sub CtrlShiftUp()
Range(ActiveCell, ActiveCell.End(xlUp)).Select
End Sub
Выделить вправо до первой или последней заполненной ячейки (равносильно нажатию Ctrl+Shift+Right)
Sub CtrlShiftRight()
Range(ActiveCell, ActiveCell.End(xlToRight)).Select
End Sub
Выделить влево до первой или последней заполненной ячейки (равносильно нажатию Ctrl+Shift+Left)
Sub CtrlShiftLeft()
Range(ActiveCell, ActiveCell.End(xlToLeft)).Select
End Sub
Выделить текущую область (выделяется диапазон неразрывно заполненных ячеек — равносильно нажатию кнопок Ctrl+Shift+*)
Sub CtrlShiftUmn()
ActiveCell.CurrentRegion.Select
End Sub
Выделить активную область (происходит выделение всего заполненного диапазона Ctrl+Shift+Home, End, Home)
Sub CtrlShiftHome()
Range(Range("A1"), ActiveCell.SpecialCells(xlLastCell)).Select
End Sub
Выделить смежные (заполненные прилегающие к активной ячейке) ячейки в столбце с активной ячейкой
Sub SelectActiveColumn()
Dim TopCell As Range
Dim BottomCell As Range
If IsEmpty(ActiveCell) Then Exit Sub
On Error Resume Next
If IsEmpty(ActiveCell.Offset(-1, 0)) Then Set TopCell = _
ActiveCell Else Set TopCell = ActiveCell.End(xlUp)
If IsEmpty(ActiveCell.Offset(1, 0)) Then Set BottomCell = _
ActiveCell Else Set BottomCell = ActiveCell.End(xlDown)
Range(TopCell, BottomCell).Select
End Sub
Выделить смежные ячейки в строке с активной ячейкой
Sub SelectActiveRow()
Dim LeftCell As Range
Dim RightCell As Range
If IsEmpty(ActiveCell) Then Exit Sub
On Error Resume Next
If IsEmpty(ActiveCell.Offset(0, -1)) Then Set LeftCell = _
ActiveCell Else Set LeftCell = ActiveCell.End(xlToLeft)
If IsEmpty(ActiveCell.Offset(0, 1)) Then Set RightCell = _
ActiveCell Else Set RightCell = ActiveCell.End(xlToRight)
Range(LeftCell, RightCell).Select
End Sub
Выделить весь активный столбец
Sub SelectionEntireColumn()
Selection.EntireColumn.Select
End Sub
Выделить всю активную строку
Sub SelectEntireRow()
Selection.EntireRow.Select
End Sub
Выделить рабочий лист
Sub SelectEntireSheet()
Cells.Select
End Sub
Выделить следующую пустую ячейку снизу
Sub CellNextDown()
ActiveCell.Offset(1, 0).Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Выделить следующую пустую ячейку справа
Sub CellNextRight()
ActiveCell.Offset(0, 1).Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(0, 1).Select
Loop
End Sub
Выделение от первой непустой до последней непустой ячеек в строке
Sub SelectFirstToLastInRow()
Dim LeftCell As Range
Dim RightCell As Range
Set LeftCell = Cells(ActiveCell.Row, 1)
Set RightCell = Cells(ActiveCell.Row, 256)
If IsEmpty(LeftCell) Then Set LeftCell = LeftCell.End(xlToRight)
If IsEmpty(RightCell) Then Set RightCell = RightCell.End(xlToLeft)
If LeftCell.Column = 256 And RightCell.Column = 1 Then ActiveCell. _
Select Else Range(LeftCell, RightCell).Select
End Sub
Выделение от первой непустой до последней непустой ячеек в столбце
Sub SelectFirstToLastInColumn()
Dim TopCell As Range
Dim BottomCell As Range
Set TopCell = Cells(1, ActiveCell.Column)
Set BottomCell = Cells(16384, ActiveCell.Column)
If IsEmpty(TopCell) Then Set TopCell = TopCell.End(xlDown)
If IsEmpty(BottomCell) Then Set BottomCell = BottomCell.End(xlUp)
If TopCell.Row = 16384 And BottomCell.Row = 1 Then ActiveCell. _
Select Else Range(TopCell, BottomCell).Select
End Sub