循环程序以将格式设置为选择中的单元格的一般问题

时间:2016-08-02 19:29:08

标签: excel vba excel-vba

我正在尝试将工作簿中多个工作表中的所有单元格的格式设置为常规格式,以便我的图表将使用显示的正确数据进行更新。这在单个活动页面上运行良好,但我无法正常循环,因为它也非常慢。

public function run(WebsiteSettings $websiteSettings) {
    if (empty($websiteSettings->key)) {
        // @TODO log this because we need to investigate why it was invoked at all 
        return false;
    }

    // Load Settings
    $settings = $websiteSettings->get_website_setting($websiteSettings->website_id, 'express-code', true);
    $has_express_enabled = ($settings && $settings->value);

    // Start the Feed Gateway
    $feedGateway = new feedGateway($websiteSettings->value, $websiteSettings->website_id, $has_express_enabled);
    $feedGateway->run();
    return true;
}

1 个答案:

答案 0 :(得分:2)

使用UsedRange限制您的数据集。

 Sub SettingFormatToGeneral()
     Dim works As Worksheet
      For Each works In ActiveWorkbook.Worksheets
        'specify the range which suits your purpose
        With works.UsedRange.Resize(, 17) '/ Only refer the used range and columns A:Q.
            .NumberFormat = "General"
            .Value = .Value
        End With
      Next works
    End Sub