VBA-ALT + Enter(换行)循环显示 [英] VBA - ALT+Enter (new line) in a Loop
问题描述
我正在编写一个宏,以便根据自动生成的报告在新的工作表中创建日历.我已经写了足够多的宏,可以在新的工作表中创建日历并突出显示与报表相对应的任何日期.现在,我想在每个周末将所有突出显示的日期写在一个单元格中.没有vba,我可以按"ALT + ENTER".但是,我当前宏的运行方式只是重新填充了最接近末尾的单元格,而不是使用行制动.我想我需要以某种方式合并chr(10),但是我不确定如何.
I am writing a macro to create a calendar in a new sheet based on an auto generated report. I have written enough of the macro to create the calendar in a new sheet and highlight any dates that correspond with the report. Now I want to write all of the highlighted dates in one cell at the end of each week. Without vba I'd be able to press "ALT + ENTER". But, the way my current macro runs it just repopulates the cell with the closest highlighted cell to the end rather than using line-brakes. I think I need to incorporate chr(10) somehow but I'm not sure how.
任何帮助将不胜感激.这是我当前的循环:
Any help would be greatly appreciated. Here is my current loop:
'find dates in August
Dim augustRng As Range
Set augustRng = Sheets("sheet1").Range("J16:P16")
For Each cell In augustRng
If cell.Interior.ColorIndex = 6 Then
cell.Select
Sheets("sheet1").Cells(16, "Q") = ActiveCell.Value
End If
Next cell
推荐答案
摆脱.Select
并将新单元格附加到Q16的原始值.
Get rid of .Select
and append the new cell to the original value of Q16.
If cell.Interior.ColorIndex = 6 Then
Sheets("sheet1").Cells(16, "Q") = Sheets("sheet1").Cells(16, "Q").Value & Chr(10) & cell.value
End If
这篇关于VBA-ALT + Enter(换行)循环显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!